from __future__ import absolute_import, unicode_literals
import os

import time
from celery import Celery

# set the default Django settings module for the 'celery' program.
#1.加载环境变量
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mall.settings')
#2.创建celery对象
app = Celery('meiduo')

#3.加载配置项
# Using a string here means the worker doesn't have to serialize
# the configuration object to child processes.
# - namespace='CELERY' means all celery-related configuration keys
#   should have a `CELERY_` prefix.
app.config_from_object('celery_tasks.config', namespace='CELERY')

# Load task modules from all registered Django app configs.
#4.注册任务  TODO  啥意思
app.autodiscover_tasks(['celery_tasks.test',"celery_tasks.sms","celery_tasks.email","celery_tasks.html"])


# @app.task(bind=True)
# def debug_task(self):
#     for i in range(0,10):
#         time.sleep(1)
#     print(i)